package io.github.lee.jel.global

import android.app.Application
import android.content.Context
import android.graphics.Typeface
import dagger.hilt.android.HiltAndroidApp
import io.github.lee.jel.domain.po.JellyfinSession
import io.github.lee.jel.global.di.database.DatabaseModule
import io.github.lee.jel.repository.JellyfinSessionRepository
import javax.inject.Inject

val Context.session: JellyfinSession?
    get() {
        val dao = DatabaseModule.provideDatabase(this)
            .jellyfinServerDao()
        return dao.queryCurrentSession()
    }

@HiltAndroidApp
class JelApplication : Application() {
    override fun onCreate() {
        super.onCreate()

//        val session = repo.queryCurrentSession()
//        if (null != session) {
//            Log.e("TAG", "app init network")
//            HttpModule.resetNetwork(session)
//        }
    }

    private fun setFonts() {
        val typeface =
            Typeface.createFromAsset(assets, "fonts/AlimamaDongFangDaKai-Regular.ttf");

        try {
            val typefaceField = Typeface::class.java.getDeclaredField("MONOSPACE")
            typefaceField.isAccessible = true
            typefaceField.set(null, typeface)
        } catch (e: Exception) {
            e.printStackTrace()
        }


    }
//    private void changeTTF() {
//        Typeface typefaceALTAN = Typeface.createFromAsset(getAssets(), "fonts/ALTAN.TTF");
//        try {
//            Field typefaceField = Typeface.class.getDeclaredField("MONOSPACE");
//            typefaceField.setAccessible(true);
//            typefaceField.set(null,typefaceALTAN);
//        }catch (Exception e){}
//    }
}